package com.enterprise.projectManager.rope;

import com.enterprise.projectManager.model.PayProgress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.sql.Date;
import java.util.List;

public interface PayProgressRope extends JpaRepository<PayProgress,String> {
//    Optional<Contract> findByContractName (String contractName) ;
//    List<Contract> findByContractState (String contractState) ;
//    Optional<Contract> findByContractNature (String contractNature) ;
    @Query("SELECT p from PayProgress p where " +
            "(:name is null or p.contract.contractName like %:name% )"+
            "and (:type is null or p.contract.contractType = :type)"+
            "and (:minCost is null or p.contract.contractCost >= :minCost )"+
            "and (:maxCost is null or p.contract.contractCost <= :maxCost )"+
            "and (:firstCompany is null or p.contract.contractFirstcompany = :firstCompany )"+
            "and (:secondCompany is null or p.contract.contractSecondcompany = :secondCompany )"+
            "and (:status is null or p.contract.contractState = :status)"+
            "and (:payPlan is null or p.payPlan = :payPlan )"+
            "and (:payStartDate is null or p.payDate >= :payStartDate)"+
            "and (:payEndDate is null or p.payDate <= :payEndDate)"+
            "and (:signStartDate is null or p.contract.contractSigndate >= :signStartDate)"+
            "and (:signEndDate is null or p.contract.contractSigndate <= :signEndDate)"
    )
    List<PayProgress> filterPayProgress(@Param(value = "name") String name,
                                        @Param(value = "type") String type,
                                        @Param(value = "minCost") Double minCost,
                                        @Param(value = "maxCost") Double maxCost,
                                        @Param(value = "firstCompany") String firstCompany,
                                        @Param(value = "secondCompany") String secondCompany,
                                        @Param(value = "status") String status,
                                        @Param(value = "payPlan") String payPlan,
                                        @Param(value = "payStartDate") Date payStartDate,
                                        @Param(value = "payEndDate") Date payEndDate,
                                        @Param(value = "signStartDate") Date signStartDate,
                                        @Param(value = "signEndDate") Date signEndDate
    );
}
